<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/dxp/include/common-base.jsp"%>
  <title>采集管理</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

  <!-- top start -->
  <%@include file="/common/dxp/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/dxp/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
		<div id="div_hidden_content" class="hidden" style="display:none;">
			<input name="templateType" type="hidden" value="all"/>
			<div id="hidden_common_final">
				<!-- temp="hidden_common_final" start -->
				<!-- temp="hidden_common_final" end -->
			</div>
			<!-- temp="delForm_hidden" start -->
			<div id="delForm_hidden" style="display:none;">
			</div>
			<!-- temp="delForm_hidden" end -->
			<div class="form-group"><select
					id="initForm1_dxInterfaceReg_interfaceProtocol"
					class="form-control  clean"
					data-obj-name="dxExchangeProtocol" data-dict-code="dymicSql" data-type-tag="select"
					data-colmun="{value:'ptlEname',text:'ptlCname'}" data-page-name="dx-exchange-protocol" data-form-name="searchForm"
					data-def=""
					placeholder="必填项"
					data-bv-notempty="true"
					data-bv-notempty-message="不能为空">
				<option value="">--请选择--</option>
			</select></div>
			<div class="form-group"><select
					id="initForm1_dxInterfaceReg_reqMsgFormatType"
					class="form-control  clean"
					data-temp-obj="dxInterfaceReg.reqMsgFormatType"
					data-dict-code="dictItemList"
					data-dict-cate="msgFormat" data-type-tag="select"
					data-def="" placeholder="必填项"
					data-bv-notempty="true"
					data-bv-notempty-message="不能为空">
				<option value="">--请选择--</option>
			</select></div>
		</div>
      <div class="row">
        <div class="col-xs-12">
        
          <!------搜索  start ------->
          <div class="box box-solid">
             <!--搜索title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-search"></i> 数据采集管理</h3>
				  &nbsp;&nbsp;
				  <form id="logSearchForm" action="javascript:void(0);">
					  <!-- temp="searchForm_hidden" start -->
					  <div id="logSearchForm_hidden">
						  <input  type="hidden" name="indexName" value="dataanalyze">
						  <input  type="hidden" name="indexType" value="doc">
						  <input  type="hidden" name="orderCloumn" value="createdTime">
						  <input  type="hidden" name="orderSort" value="desc">
						  <input  type="hidden" name="fileList" id="es_fields" class="clean">
					  </div>
				  </form>
			  </div>
            <!--搜索title  end --> 
            <div class="box-body">
            	<form id="searchForm" action="javascript:;">
					<div class="mytab2">
						<div class="form-group"><i class="fa fa-info-circle fx8"></i> 本功能主要是针对“主动获取数据类”的接口进行数据采集处理。</div>
						<table class="table table-bordered bordercolor">
							<tbody>
							<tr>
								<td class="active w180" align="right"><label class="form-control-static">服务/接口所属系统：</label></td>
								<td class="w300">
									<div class="form-group">
										<select id="searchForm_dxSysIntRelation_sysEname"
												class="form-control  clean"
												name="dxSysIntRelation.sysEname"
												data-obj-name="dxSysReg"
												data-dict-code="dymicSql" data-type-tag="select"
												data-colmun="{value:'sysEname',text:'sysCname'}"
												data-page-name="dx-sys-reg"
												data-form-name="searchForm" data-condition=""
												data-def="" data-dict-cate="" placeholder="必填项"
												data-bv-notempty="true"
												onchange="selectInterface(this,'searchForm','searchForm_reqtest')"
												data-bv-notempty-message="不能为空">
											<option value="">--请选择--</option>
										</select>
									</div>
								</td>
								<td class="active w180" align="right"><label class="form-control-static">服务/接口名称：</label></td>
								<td >
									<div class="form-group" id="searchForm_dxSysIntRelation_fromInterfaceCode_div">
										<select
												id="searchForm_dxSysIntRelation_fromInterfaceCode"
												name="dxSysIntRelation.fromInterfaceCode"
												class="form-control  clean"
												data-temp-obj="dxSysIntRelation.fromInterfaceCode"
												data-dict-cate=""
												data-colmun="{value:'interfaceCode',text:'interfaceCode,interfaceName',other:'infoId,interfaceType,interfaceProtocol,reqMsgFormatType,respMsgFormatType,exchangeMode,exchangeType,requestWay'}"
												data-obj-name="dxInterfaceReg"
												data-page-name="dx-interface-reg"
												data-form-name="searchForm" data-condition=""
												data-type-tag="select" data-def=""
												disabled="disabled"
												onchange="changeInterface(this,'searchForm','searchForm_reqtest')">
											<option value="">--请选择--</option>
										</select>
									</div>
								</td>
							</tr>
							<tr>
								<td class="active" align="right"><label class="form-control-static">服务/接口协议：</label></td>
								<td>
									<div class="form-control-static"><span name="dxSysIntRelation.interfaceProtocol"></span></div>
								</td>
								<td class="active" align="right"><label class="form-control-static">格式类型：</label></td>
								<td>
									<div class="form-control-static"><span name="dxSysIntRelation.reqMsgFormatType"></span></div>
								</td>
							</tr>
							<tr>
								<td class="active" align="right">
									<label class="form-control-static">请求body参数值：</label>
									<div class="form-group"><i class="fa fa-info-circle fx8"></i> 请根据实际情况配置参数值</div>
								</td>
								<td colspan="3" class="mytab3">
									<table id="table_req_searchForm" req-test-form-id="searchForm_reqtest" class="table table-bordered" style="margin-bottom: 9px;">
										<tbody class="show_req_msg_div">

										</tbody>
									</table>
								</td>
							</tr>
							</tbody>
						</table>
					</div>
			  	</form>
				<form id="searchForm_reqtest" action="javascript:void(0)" style="margin-top:-21px;">
					<input type="hidden" name="requestUrl"/>
					<input type="hidden" name="appId">
					<div class="mytab2">
						<table class="table table-bordered bordercolor">
							<tbody>
							<tr>
								<td class="active w180" align="right"><label class="form-control-static">请求Params参数值：</label></td>
								<td colspan="5">
									<div class="form-group">
										<textarea  class="form-control" name="urlParams" rows="2" placeholder="非必填param，可输入接口所需的其他参数"></textarea>
										<div class="f11 fx1">多个参数使用“&”分割，格式参考：key1=value1&key2=value2&key3=value3</div>
									</div>
								</td>
							</tr>
							<tr class="hidden">
								<td class="active w180" align="right"><label class="form-control-static">实际请求报文：</label></td>
								<td>
									<div class="form-group">
										<textarea  class="form-control" name="testMsg" rows="2"></textarea>
									</div>
								</td>
							</tr>
							</tbody>
						</table>
					</div>
				</form>
			  <div class="box-footer text-center">
				  <button class="btn btn-warning pull-right" type="button" onclick="toSubmitTest('searchForm','searchForm_reqtest');"><i class="fa fa-edit"></i> 开始采集</button>
			   </div>
            </div>
	     </div>
	     <!------- 搜索 end -------->
           
        <!------- 列表 start -------->
          <div class="box box-solid">
            <!--列表title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-table"></i> 本接口全部采集所解析的结果  [共计<span id="dataListTotalCount">0</span>条数据]</h3>
				  <button class="btn btn-success" onclick="getTableData()"><i class="fa fa-search-plus"></i> 开始查询</button>
                 <div class="box-tools pull-right">
<%--    				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>--%>
 				 </div>
              </div>
			  <div class="box-body mytab2">
				  <table id="analyzedataList" class="table table-bordered table-hover">
					  <thead>
					  <tr>
						  <th>序号</th>
						  <th>数据rowkey</th>
						  <th>服务/接口编号</th>
						  <th>解析时间</th>
						  <th>操作</th>
					  </tr>
					  </thead>
					  <tbody id="analyzedataList-body">

					  </tbody>
				  </table>
            	</div>
           	 	
           	 	<div class="box-footer text-center">
			      	<ul id="analyzedataList-page" class="pagination">
					</ul>
			 	</div>              
           </div>
        <!------- 列表 end -------->
        </div>
      </div>
  
<div win-title="采集配置窗口" class="modal fade" id="my_modal_add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:95%;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							×
						</button>
						<h4 class="modal-title">
							<font color="red">继续采集配置</font> 
						</h4>
					</div>

					<div class="modal-body">
						
					       <div class="nav-tabs-custom">
					            <ul class="nav nav-tabs" id="myTab-add">
					            </ul>
					              
					            <!-- tab content start -->
					            <div class="tab-content">
					            
					               <div class="tab-pane active" id="tabAdd_1">
									   <div class="row">
										   <div class="col-lg-4">
											   <div class="f12 fb">前置接口[<span class="red" id="span_last_req_inft"></span>]解析后数据如下：</div>

											   <div>
                                                   <input id="tabAdd_1_res_msg_input" type="hidden" />
												   <pre style="height:460px; font-size: 12px; overflow-y: scroll;overflow-x: scroll; "><code id="tabAdd_1_res_msg"></code></pre>
											   </div>
										   </div>
										   <div class="col-lg-8">
											   <form class="form-horizontal addFormBody" role="form" id="addForm1" action="javascript:void(0)">
												   <div id="addForm1_content"  class="mytab2">
													   <table class="table table-bordered bordercolor">
														   <tbody>
														   <tr>
															   <td class="active" style="width:100px" align="right"><label class="form-control-static">服务/接口所属系统：</label></td>
															   <td class="w150">
																   <div class="form-group">
																	   <select id="addForm1_dxSysIntRelation_sysEname"
																			   class="form-control  clean"
																			   name="dxSysIntRelation.sysEname"
																			   data-obj-name="dxSysReg"
																			   data-dict-code="dymicSql" data-type-tag="select"
																			   data-colmun="{value:'sysEname',text:'sysCname'}"
																			   data-page-name="dx-sys-reg"
																			   data-form-name="searchForm" data-condition=""
																			   data-def="" data-dict-cate="" placeholder="必填项"
																			   data-bv-notempty="true"
																			   onchange="selectInterface(this,'addForm1','addForm1_reqtest')"
																			   data-bv-notempty-message="不能为空">
																		   <option value="">--请选择--</option>
																	   </select>
																   </div>
															   </td>
															   <td class="active" style="width:100px" align="right"><label class="form-control-static">服务/接口名称：</label></td>
															   <td >
																   <div class="form-group" id="addForm1_dxSysIntRelation_fromInterfaceCode_div">
																	   <select
																			   id="addForm1_dxSysIntRelation_fromInterfaceCode"
																			   name="dxSysIntRelation.fromInterfaceCode"
																			   class="form-control  clean"
																			   data-temp-obj="dxSysIntRelation.fromInterfaceCode"
																			   data-dict-cate=""
																			   data-colmun="{value:'interfaceCode',text:'interfaceCode,remark',other:'infoId,interfaceType,interfaceProtocol,reqMsgFormatType,respMsgFormatType,exchangeMode,exchangeType,requestWay'}"
																			   data-obj-name="dxInterfaceReg"
																			   data-page-name="dx-interface-reg"
																			   data-form-name="searchForm" data-condition=""
																			   data-type-tag="select" data-def=""
																			   disabled="disabled"
																			   onchange="changeInterface(this,'addForm1','addForm1_reqtest')">
																		   <option value="">--请选择--</option>
																	   </select>
																   </div>
															   </td>
														   </tr>
														   <tr>
															   <td class="active" align="right"><label
																	   class="form-control-static">接口协议：</label></td>
															   <td>
																   <div class="form-control-static"><span name="dxSysIntRelation.interfaceProtocol"></span></div>
															   </td>
															   <td class="active" align="right"><label
																	   class="form-control-static">格式类型：</label></td>
															   <td>
																   <div class="form-control-static"><span name="dxSysIntRelation.reqMsgFormatType"></span></div>
															   </td>
														   </tr>
														   <tr>
															   <td class="active" align="right">
																   <label class="form-control-static">请求body参数值：</label>
																   <div class="form-group"><i class="fa fa-info-circle fx8"></i> 请根据实际情况配置参数值</div>
															   </td>
															   <td colspan="3" class="mytab3">
																   <table  id="table_req_addForm1" req-test-form-id="addForm1_reqtest" class="table table-bordered" style="margin-bottom: 9px;">
																	   <tbody class="show_req_msg_div">
																	   </tbody>
																   </table>
															   </td>
														   </tr>
														   </tbody>
													   </table>
												   </div>
											   </form>
											   <form id="addForm1_reqtest" action="javascript:void(0)" style="margin-top:-21px;">
												   <input type="hidden" name="requestUrl"/>
												   <input type="hidden" name="appId">
												   <div  class="mytab2">
													   <table class="table table-bordered bordercolor">
														   <tbody>
														   <tr>
															   <td class="active" style="width:180px" align="right"><label class="form-control-static">请求Params参数值：</label></td>
															   <td>
																   <div class="form-group">
																	   <textarea  class="form-control" name="urlParams" rows="2" placeholder="非必填param，可输入接口所需的其他参数"></textarea>
																	   <div class="f11 fx1">多个参数使用“&”分割，格式参考：key1=value1&key2=value2&key3=value3</div>
																   </div>
															   </td>
														   </tr>
														   <tr class="hidden">
															   <td class="active" align="right"><label class="form-control-static">实际请求报文：</label></td>
															   <td>
																   <div class="form-group">
																	   <textarea  class="form-control" name="testMsg" rows="2"></textarea>
																   </div>
															   </td>
														   </tr>
														   </tbody>
													   </table>
												   </div>
											   </form>
											   <div class="box-footer text-center">
												   <button class="btn btn-warning pull-right" type="button" onclick="toSubmitTest('addForm1','addForm1_reqtest');"><i class="fa fa-edit"></i> 开始采集</button>
											   </div>
										   </div>
									   </div>
					               </div>

				            </div>
					            <!-- tab content e -->
				          </div>	
			                
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>
<div win-title="查看窗口" class="modal fade" id="my_modal_view" tabindex="-2" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:80%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                </button>
                <h4 class="modal-title">
                    <font color="red">解析数据详情</font> 
                </h4>
            </div>
            <div class="modal-body viewForm">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs" id="myTab-view">
                    </ul>
                    <!-- tab content start -->
                    <div class="tab-content">
                        <div class="tab-pane active" id="tabView_1">
                            <form class="form-horizontal" role="form" id="viewForm1"  action="javascript:void(0)">
                                <div id="viewForm1_content">
                                    <table id="viewForm1_table" class="table bordercolor table-bordered">
                                        <thead> </thead>
                                        <tbody> </tbody>
                                    </table>
                                </div>
                            </form>
                            <div class="form-group">
                            </div>
                        </div>
                    </div>
                    <!-- tab content e -->
                </div>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
</div>
<!-- Part 二、以下是template模板定义的模块区域 -->
<script type="text/template" id="analyzedataList-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr>
		<td><?=(pageObj.currentPage-1)*pageObj.rows+(i+1)?></td>
		<!-- temp="dataList_template_content" start -->
		<td title="<?=rows[i].rowkey?>"><?=strUtil.subStr(rows[i].rowkey,10)?></td>
		<td><?=dictListMap['dx-interface-reg-searchForm'][rows[i].interfaceCode]?></td>
		<td><?=getFormatDateByLong(rows[i].createdTime,"yyyy-MM-dd hh:mm:ss")?></td>
		<!-- temp="dataList_template_content" end -->
		<td>
			 <button type="button" class="btn btn-success btn-xs" row-key="<?=rows[i].rowkey?>" onclick="toLoad('<?=rows[i].rowkey?>','<?=rows[i].tableName?>','<?=rows[i].interfaceCode?>')">
            <i class="fa fa-search-plus"></i> 查看详情
            </button> &nbsp;
			<button type="button" class="btn btn-primary btn-xs" row-key="<?=rows[i].rowkey?>" onclick="toAdd('<?=rows[i].rowkey?>','<?=rows[i].tableName?>','<?=rows[i].interfaceCode?>')">
				<i class="fa fa-edit"></i> 继续采集
			</button>
		</td>
	</tr>
	<?}?>
</script>

<script type="text/template" id="loopinput-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr>
		<td class="w120" align="right"><div class="form-control-static"><?=rows[i].key?></div></td>
		<td>
			<div class="form-group">
				<?if(rows[i].valueType=='object'){?>
					<textarea data-value-type="<?=rows[i].valueType?>" data-param="true" onblur="appendInputToJson(this)" rows="2" name="<?=rows[i].key?>" class="form-control clean"><?=rows[i].value?></textarea>
				<?}else{?>
					<input data-value-type="<?=rows[i].valueType?>" data-param="true" onblur="appendInputToJson(this)" type="text" name="<?=rows[i].key?>" class="form-control clean" value="<?=rows[i].value?>"/>
				<?}?>
			</div>
		</td>
	</tr>
	<?}?>
</script>

<!-- Part 三、 以下是js模块区域 -->
<script>
var clickMenu = "collect-list";
var myPage,dataListId,searchFormId;
myPage = 10;//定义列表数据
dataListId = "analyzedataList";//显示列表数据div的id
searchFormId = "logSearchForm";//搜索表单Id
var searchForm_input_interfaceCode='',searchResultDataHead=[];
var tableListMap= {};
/**
 * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
 */
var dictListMap = DictUtil.initDictAndDymic();
 
$(function () {
	//1、加载分页列表数据

	cleanDivContent('searchForm','searchForm_reqtest');
	
	//2、控制是否启用token
	//setToken();
	
 });

//选择服务单位加载该单位系统下对应的接口列表
function selectInterface(obj,formId,reqFormId) {
	$("#"+formId).find("span").text("");
	cleanDivContent(formId,reqFormId);
	var option = $(obj).find("option:selected");
	var selectInterfaceCodeObj =$("#"+formId+"_dxSysIntRelation_fromInterfaceCode");
	selectInterfaceCodeObj.html("<option value=\"\">--请选择--</option>");
	if(!strUtil.isNull(option.val())){
		selectInterfaceCodeObj.attr("data-condition","dxInterfaceReg.w_sysEname="+option.val()+"&dxInterfaceReg.exchangeMode=12");//只是查主动获取类接口
		selectInterfaceCodeObj.attr("disabled",false);
		selectInterfaceCodeObj.attr("data-dict-code","dymicSql");
		delete dictListMap['dx-interface-reg-searchForm'];
		DictUtil.initDictAndDymic("#"+formId+"_dxSysIntRelation_fromInterfaceCode_div");
	}else {
		selectInterfaceCodeObj.attr("data-condition","");
		selectInterfaceCodeObj.attr("disabled",true);
		selectInterfaceCodeObj.removeAttr("data-dict-code");
	}
}
function cleanDivContent(formId,reqFormId) {
	$("#"+formId).find(".show_req_msg_div").html("");
	$("#"+reqFormId).addClass("hidden");
	$("#"+reqFormId).find("textarea[name='urlParams']").val('');
	$("#"+reqFormId).find("textarea[name='testMsg']").val('');
	if(formId=='searchForm'){
        $("#analyzedataList-body").html("");
        $("#analyzedataList-page").html('');
        $("#dataListTotalCount").text('0');
        searchForm_input_interfaceCode='';
	}
	// searchResultDataHead=[];

}
//加载接口数据
function changeInterface(obj,formId,reqFormId) {
	// console.log(obj,"obj");
	$("#"+formId).find("span").text("");
	cleanDivContent(formId,reqFormId);
	var option = $(obj).find("option:selected");
	var faceCodeVal = option.val();
	// console.log(option,"option");
	if(!strUtil.isNull(faceCodeVal)){
		var interfaceProtocol = option.attr("interface-protocol");
		var reqMsgFormatType = option.attr("req-msg-format-type");
		var respMsgFormatType = option.attr("resp-msg-format-type");
		var interfaceType = option.attr("interface-type");
		var exchangeMode = option.attr("exchange-mode");
		var infoId = option.attr("info-id");
		var exchangeType = option.attr("exchange-type");
		var requestWay = option.attr("request-way");
		interfaceProtocol = dictListMap["dx-exchange-protocol-searchForm"][interfaceProtocol];
		reqMsgFormatType = dictListMap["msgFormat"][reqMsgFormatType];
		$("#"+formId).find("span[name='dxSysIntRelation.interfaceProtocol']").text(interfaceProtocol+" ["+requestWay+"] ");
		$("#"+formId).find("span[name='dxSysIntRelation.reqMsgFormatType']").text(reqMsgFormatType);

		selectMsgFormat(formId,reqFormId,infoId,"show_req_msg_div",reqMsgFormatType,"req");
		selectMsgFormatParams(formId,reqFormId,infoId,"params");
        if(formId=='searchForm') {
            searchForm_input_interfaceCode = faceCodeVal;
        }

		var index_load = layer.load(1, {shade: false});
		// getTableHeadShowField();//获取结果表头

		//查询接口请求地址：
		var sysEname = $("#"+formId+"_dxSysIntRelation_sysEname").find("option:selected").val();
		var paramLoadData={};
		paramLoadData["pageName"] = "dx-sys-int-relation-search";
		paramLoadData["formName"] = "searchForm";
		paramLoadData["dxSysIntRelation.w_sysEname"] = sysEname;
		paramLoadData["dxSysIntRelation.w_fromInterfaceCode"] = faceCodeVal;
		$.ajax({
			type:"get",
			url:common_info_url,
			data: paramLoadData,dataType:"json",
			success: function(myData){
				layer.close(index_load);
				var requestUrl = myData['dxSysIntRelation'].requestUrl;
				var appId =  myData['dxSysIntRelation'].toServerId;
				$("#"+reqFormId).find("input[name='requestUrl']").val(requestUrl);
				$("#"+reqFormId).find("input[name='appId']").val(appId);
				console.log('dxSysIntRelation',myData,'requestUrl',requestUrl,'appId',appId);
				// getTableData();
			}
		});
	}
}
//查询报文格式
function selectMsgFormat(formId,reqFormId,infoId,codeId,msgFormatType,msgType) {
	$("#"+codeId).html("");
	var paramLoadData={};
	paramLoadData["pageName"] = "dx-msg-format-set-search";
	paramLoadData["formName"] = "searchForm";
	paramLoadData["interfaceId"] = infoId;
	paramLoadData["msgFormatType"] = msgFormatType;
	paramLoadData["msgType"] = msgType;
	var index_load = layer.load(1, {shade: false});
	$.get(common_info_url, paramLoadData, function (myData) {
		layer.close(index_load);
		console.log("dx-msg-format-set.body.res",myData);
		if(myData.result=="T"){
			var resDatas = myData.entity;
			$("#"+reqFormId).find("textarea[name='testMsg']").val(JSON.stringify(resDatas));
			if("json"==msgFormatType){
				if(!strUtil.isNull(resDatas)){
					if(formId=='addForm1'){//继续采集时，匹配前置接口返回的同名key对应值
						var tabAdd_1_res_msg_data_val = $("#tabAdd_1_res_msg_input").val();
						if(!strUtil.isNull(tabAdd_1_res_msg_data_val)){
							mytools.matchRestByParams(resDatas,JSON.parse(tabAdd_1_res_msg_data_val));
						}
					}
					var dataRows = [];
					for(var keys in  resDatas){
						var valueType = "string";
						var value =resDatas[keys];
						if(typeof(value) == 'string'){
							value =resDatas[keys];
						}else{
							valueType="object";
							value=JSON.stringify(value);
						}
						var items = {key:keys,value:value,valueType:valueType};
						dataRows.push(items);
					}
					var loopinputData = {rows:dataRows};
					var loopinputDataHtml = baidu.template("loopinput-template",eval(loopinputData));
					console.log(formId+".loopinputData",loopinputData);
					$("#"+formId).find(".show_req_msg_div").html(loopinputDataHtml);

					if(formId=='addForm1'){//组装最新请求参
						appendReqDataParam($('#table_req_'+formId));
					}
				}
			}else{
				mytools.showXmlFormat(codeId,resDatas);
			}
			$("#"+reqFormId).removeClass("hidden");
		}else{
			$("#"+codeId).html("暂未配置报文格式。");
		}
	}, "json");
}
function selectMsgFormatParams(formId,reqFormId,interfaceId,msgType) {
	var paramLoadData={};
	paramLoadData["pageName"] = "dx-msg-format-set";
	paramLoadData["formName"] = "searchForm";
	paramLoadData["dxMsgFormatSet.w_interfaceId"] = interfaceId;
	paramLoadData["dxMsgFormatSet.w_msgType"] = msgType;
	$.get(common_list_url, paramLoadData, function (myData) {
		console.log("dx-msg-format-set.params.res",myData);
		if(myData.flag=="T") {
			if (myData.total > 0) {
				var paramsStr = "";
				for (var i = 0; i < myData.total; i++) {
					var paramEname = myData.rows[i].paramEname;
					var defValue = strUtil.doNull(myData.rows[i].defValue, "");
					paramsStr += "&" + paramEname + "=" + defValue;
				}
				paramsStr = paramsStr.substr(1, paramsStr.length);
				$("#" + reqFormId).find("textarea[name='urlParams']").val(paramsStr);
			} else {
				$("#" + reqFormId).find("textarea[name='urlParams']").val('');
				$("#" + reqFormId).find("textarea[name='urlParams']").attr("placeholder", "暂无相关参数")
			}
			$("#"+reqFormId).removeClass("hidden");
		}
	}, "json");
}
function appendInputToJson(ob) {
	var tableId = $(ob).parents("table").attr("id");
	var $table=$("#"+tableId);
    appendReqDataParam($table);
}
function appendReqDataParam($table) {
    if($table){
        var reqFormId = $table.attr("req-test-form-id");
        var paramMap = {};
        $table.find("[data-param='true']").each(function () {
            var attrKeys = $(this).attr('name');
            var attrVal = $(this).val();
            var valueType = $(this).attr('data-value-type');
            if(valueType=='object'){
                attrVal=JSON.parse(attrVal);
            }
            paramMap[attrKeys] = attrVal;
        });
        $("#"+reqFormId).find("textarea[name='testMsg']").val(JSON.stringify(paramMap));
    }
}
function toSubmitTest(formId,reqFormId) {
	var testMsg_vals = $("#"+reqFormId).find("textarea[name='testMsg']").val();
	var urlParams_vals = $("#"+reqFormId).find("textarea[name='urlParams']").val();
	if(strUtil.isNull(testMsg_vals)&&strUtil.isNull(urlParams_vals)){
		layer.msg("请先选择接口和相关参数！");
		return;
	}
	console.log('toSubmitTest.req',formId,reqFormId,testMsg_vals,urlParams_vals);
	var index_submit = layer.confirm("您确定开始采集以上所选接口的数据吗？", {btn: ["Yes", "No"], closeBtn: 0, offset: "220px"}
	, function () {
		layer.close(index_submit);
		var index_msg=layer.msg("数据采集进行中...",{time: -1 });
		$.ajax({
			type: 'post',url: ctx+'/api/toTest?f='+new Date().getTime(),
			data:$("#"+reqFormId).serialize(),dataType: 'json',
			success: function (myData) {
				layer.close(index_msg);
				console.log('toTest.res',myData);
				if("200"==myData.errorCode){
					layer.alert("已采集完成，正在解析结果，请耐心等待10s后再查询解析结果！");
					// getTableData();
				}else{
					layer.msg("采集失败："+myData.errorMessage);
				}

			},
			error:function(jqXHR, textStatus, errorThrown){
				layer.close(index_msg);
				console.log('toSubmitTest.error',textStatus);
			}
		});
	});
}

 $(function () {
	//设置数据行选中效果
	$('#'+dataListId+' tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     //var id = $('tr.selected th').eq(0).html();
	} );
 });

//打开添加modal
function toAdd(rowKey,tableName,interfaceCode){
	var detailObj = getEsSearchHbaseByRowKey(rowKey,tableName,interfaceCode);
	mytools.showJsonViewer(detailObj,"tabAdd_1_res_msg");
	$("#tabAdd_1_res_msg_input").val(JSON.stringify(detailObj));
	mytools.cleanData(".addFormBody");//清空表单元素上次填写的内容；
	$("#my_modal_add").modal("show");
	$('#span_last_req_inft').text(interfaceCode);
	cleanDivContent('addForm1','addForm1_reqtest');
}
//数据toLoad读取（查看、编辑）数据
function toLoad(rowKey,tableName,interfaceCode) {
    $("#my_modal_view").modal("show");
    var index_load = layer.load(1, {shade: false});
    //获取列头
    $.get(common_list_url, {"pageName":"dx-msg-format-set","formName":"searchForm","dxMsgFormatSet.w_interfaceCode":interfaceCode,"dxMsgFormatSet.w_ifUse":"1","result_column":"dxMsgFormatSet.cloumEname,dxMsgFormatSet.paramEname,dxMsgFormatSet.paramCname"}, function (myData2) {
        console.log(myData2,"myData2");
        var headArray=myData2.rows;
		if('1'==common_sys_version_mode){
			//简版不走hbase
			var data = tableListMap[rowKey].message;
			// console.log(data,"data--fpc");
			//反显加载数据
			if (data) {
				var tableOptions = {
					tableObj:$("#viewForm1_table"),
					bodyData:data,
					titleConf:headArray,
					titleConfKey:'cloumEname',
					titleConfText:'paramCname',
					titleClass:'active w150'
				};
				console.log(tableOptions,"fpc-table");
				mytools.loadTableDynamicByInfo(tableOptions);
			}
			layer.close(index_load);
		}else {
			//反显加载数据
			$.get(ctx + "/api/esSearchHbaseByRowKey", {
				"rowKey": rowKey,
				"tableType": "dataanalyze",
				"tableName": tableName
			}, function (myData) {
				console.log("toLoad.myData", myData);
				layer.close(index_load);
				//反显加载数据
				var tableOptions = {
					tableObj: $("#viewForm1_table"),
					bodyData: myData.data,
					titleConf: headArray,
					titleConfKey: 'cloumEname',
					titleConfText: 'paramCname',
					titleClass: 'active'
				};
				mytools.loadTableDynamicByInfo(tableOptions);
			}, "json");
		}
    }, "json");


}

//加载列表数据
function getTableData() {
	if(strUtil.isNull(searchForm_input_interfaceCode)){
		layer.msg("请先选择要查询的服务接口！");
		return;
	}
	var flag=false;
	var fileList =[];
	var file={};
	var interfaceCode = searchForm_input_interfaceCode;
	if(interfaceCode){
		file={};
		file["fileName"]="interfaceCode";
		file["fileValue"]="*"+interfaceCode+"*";
		file["searchType"]="wildcard";
		flag=true;
		fileList.push(file);
	}
	console.log('esSearchPageList.req.fileList',fileList);
	if(flag){
		$("#" + searchFormId).find("input[name='fileList']").val(JSON.stringify(fileList))
	}else {
		layer.msg("请输入查询条件");
		return;
	}
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type: 'get',
		url: ctx+"/api/esSearchPageList?f="+new Date().getTime(),
		data: $("#" + searchFormId).serialize() + getCurrentPage(ctx+"/api/esSearchPageList?" + $("#" + searchFormId).serialize(), myPage),
		// contentType:'application/json',
		dataType: 'json',
		success: function (myData) {
            console.log('esSearchPageList.res', myData);
            if (myData) {
                $("#dataListTotalCount").text(myData.total);
                if ("T" == myData.flag) {
                    // getDetailAsTable(myData.rows);//特殊处理，未使用
                    var data = baidu.template(dataListId + "-template", eval(myData));
                    $("#" + dataListId + "-body").html(data);
                    var option = {
                        ele: $("#" + dataListId + "-page")[0],
                        total: myData.total,
                        fn: getTableData,
                        url: ctx + "/api/esSearchPageList?" + $("#" + searchFormId).serialize()
                    };
                    generatePages(option);
					if(myData.total>0){
						saveTableListMapData(myData.rows);
					}
                }
                layer.close(index_load);
            }else{
                layer.close(index_load);
                layer.msg("请求失败，请稍后重试！")
            }
        },
		error: function (jqXHR, textStatus, errorThrown) {
			layer.msg(textStatus);
		}
	});
}
function saveTableListMapData(data){
	// console.log(data,"fpc001");
	for (var i=0;i<data.length;i++){
		var key = data[i].es_metadata_id;
		// console.log(key,"key");
		tableListMap[key]=data[i];
	}
}
//详情合并到列表显示
function getDetailAsTable(myData) {
	for(var j=0;j<myData.length;j++) {
		var czdata = myData[j];
		var detailObj = getEsSearchHbaseByRowKey(czdata.rowkey,czdata.tableName,czdata.interfaceCode);
		for(var a in detailObj){
			myData[j][a]=detailObj[a];
		}
	}
	console.log('esSearchPageList.new',myData);
	var tableOptions = {
		tableObj:$("#analyzedataList"),
		headArray:searchResultDataHead,
		bodyData:{rows:myData},
	};
	mytools.loadTableDynamicByList(tableOptions);
}
//查找可显示表头
function getTableHeadShowField() {
	$.ajax({
		type:"get",
		async:false,
		url:common_list_url,
		data: {
			"pageName": "dx-msg-format-set",
			"formName": "searchForm",
			"dxMsgFormatSet.w_interfaceCode": searchForm_input_interfaceCode,
			"dxMsgFormatSet.w_ifUse": "1",
			"result_column": "dxMsgFormatSet.paramEname,dxMsgFormatSet.paramCname"
		},
		dataType:"json",
		success: function(myData){
			console.log('getTableHeadShowField.res',myData);
			if(myData.flag=='T'){
				for(var k in myData.rows){
					searchResultDataHead.push(myData.rows[k].paramEname);
				}
			}
		}
	});
}
function getEsSearchHbaseByRowKey(rowKey,tableName,interfaceCode) {
	// var index_load = layer.load(1, {shade: false});
	var detailObj = {};
	if('1'==common_sys_version_mode){
		//简版不走hbase
		detailObj = tableListMap[rowKey].message;
		// console.log(data,"data--fpc");
	}else {
		$.ajax({
			async: false,
			url: ctx + "/api/esSearchHbaseByRowKey",
			data: {"rowKey": rowKey, "tableType": "dataanalyze", "tableName": tableName},
			dataType: "json",
			success: function (myData) {
				// layer.close(index_load);
				console.log('getEsSearchHbaseByRowKey.res', myData);
				if (myData.flag == 'T') {
					detailObj = myData.data;
				}
			}
		});
	}
	return detailObj;
}

//提交tab1表单数据
function submitForm1(formId,tabId){
	//校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过就返回
	    return;  
	}
	
	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		var result = submitForm(formId,tabId);
		if(result){
			layer.alert("提交成功！", {closeBtn: 0 });
      		mytools.closeModal("my_modal_add");
      		mytools.closeModal("my_modal_edit");
      		refresh();
		
    		
      		setToken();
    		if(!strUtil.isNull(tabId)){
      			$('.nav-tabs a[href=\"#'+tabId+'\"]').tab('show'); // Select tab by name 
      		}
	  	}
	});
	
 }
//提交表单数据
function submitForm(formId,tabId){
	var result;
	var index_load = layer.load(1, {shade: false});
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    async:false,
	    dataType:'json',
	    success: function(myData){ 
	     console.log(myData);
	        if(myData.flag=="T"){
	        	result = myData;
	    	}else{
	    		setToken();
	     		layer.alert(myData.msg);
	    	}
	        layer.close(index_load);
	  	},
	     error: function (e) {
		     layer.close(index_load);
     	} 
	});	
	return result;
}

//刷新
function refresh(){
	getTableData();
}
//设置token
function setToken(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	console.log(myData);
			$('.formToken').val(myData);
	  	}
	});	
}


/**** Part 四、以下是自定义新增方法  ****/
//1.定义校验规则-定义
function setValidate(id){
	$(id).each(function(){
		$(this).bootstrapValidator({
		    feedbackIcons: {
		        valid: 'glyphicon glyphicon-ok',
		        invalid: 'glyphicon glyphicon-remove',
		        validating: 'glyphicon glyphicon-refresh'
		    },/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
		 	fields:{
		 		/** 可自定义新增验证规则
		    	"uctUser.userEname":{
		    		 validators: {
		    			 regexp: {
		    				 regexp: /^[0-9]+$/,
		                      message: '只能是数字'
		                  }
		              }
		    	}
		    	**/
				}
		});
	});
}


</script>
</section>
<!-- Main end -->   
</div>
<!-- foot start -->
<%@include file="/common/dxp/foot.jsp" %>
<!-- foot start -->
</div>
<!-- /.content-wrapper -->
</body>
</html>

